﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseLinQ.DataContex;
using Module;

namespace Solutions.Admin.Report
{
    public partial class danhsachnguoidung : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ReportViewer1.Report = CreateReport();
        }
       
        public DevExpress.XtraReports.UI.XtraReport CreateReport()
        {
            rp_BaoCaoChucNang baoCaoChucNang = new rp_BaoCaoChucNang();
            MenuLogic menuLogic = new MenuLogic();
             List<tbl_Menu> lstMenu = menuLogic.GetTreeMenu();
             if (lstMenu != null && lstMenu.Count > 0)
             {DataTable dt = ConvertToDataTable(lstMenu);
                baoCaoChucNang.BindData(dt);
             }

             return baoCaoChucNang;
        }
        public DataTable ConvertToDataTable<T>(IList<T> data)
        {
            PropertyDescriptorCollection properties =
               TypeDescriptor.GetProperties(typeof(T));
            DataTable table = new DataTable();
            foreach (PropertyDescriptor prop in properties)
                table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
            foreach (T item in data)
            {
                DataRow row = table.NewRow();
                foreach (PropertyDescriptor prop in properties)
                    row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
                table.Rows.Add(row);
            }
            return table;

        }
    }
}